﻿<UserControl x:Class="XERP.Client.WPF.CompanyMaintenance.Views.TypeMaintenanceView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
            d:DesignHeight="350" d:DesignWidth="650"
             IsEnabled="{Binding Path=FormIsEnabled}" Loaded="UserControl_Loaded" PreviewKeyUp="UserControl_PreviewKeyUp">

    <Grid Style="{StaticResource BaseGrid}">
        <Grid.RowDefinitions>
            <RowDefinition Height="50"></RowDefinition>
            <RowDefinition Height="550*"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="156"></ColumnDefinition>
            <ColumnDefinition Width="422*"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <TextBlock Style="{StaticResource BaseHeader}"
            HorizontalAlignment="Left" Grid.Column="1" Text="Company Type Maintenance Form"
            Margin="138,10,0,5" >
        </TextBlock>
        <StackPanel Style="{StaticResource BaseStackPanel}"
            Orientation="Vertical"  Width="271"  Height="50" Grid.ColumnSpan="2"
            HorizontalAlignment="Left" VerticalAlignment="Top">
            <Menu Style="{StaticResource BaseMenu}"
                IsMainMenu="True" Grid.ColumnSpan="2" Width="250" Height="20" 
                VerticalAlignment="Top" HorizontalAlignment="Left">
                <MenuItem Style="{StaticResource BaseMenuItem}" Header="_File">
                    <MenuItem Style="{StaticResource BaseMenuItem}" Header="_New">
                        <MenuItem Style="{StaticResource BaseMenuItem}" Name="mnuNewCompanyType" 
                                  Header="_New Company Type" IsEnabled="{Binding AllowNew}">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <ei:CallMethodAction
                                    TargetObject="{Binding}"
                                    MethodName="NewCompanyTypeCommand"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </MenuItem>
                    </MenuItem>
                    <MenuItem Style="{StaticResource BaseMenuItem}"  Header="_Save" Name="mnuSave"
                              Click="SaveMenuItem_Click" >
                        
                    </MenuItem>
                    <MenuItem Style="{StaticResource BaseMenuItem}" Header="_Delete" >
                        <MenuItem Style="{StaticResource BaseMenuItem}" Header="_Delete Company Type" 
                                  IsEnabled="{Binding AllowDelete}">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <ei:CallMethodAction
                                    TargetObject="{Binding}"
                                    MethodName="DeleteCommand"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </MenuItem>
                    </MenuItem>
                    <MenuItem Style="{StaticResource BaseMenuItem}" Header="_Exit" 
                              Command="Close"/>
                </MenuItem>
                <MenuItem Style="{StaticResource BaseMenuItem}" Header="_Edit">
                    <MenuItem Style="{StaticResource BaseMenuItem}" Header="_Clear">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Click">
                                <ei:CallMethodAction
                                TargetObject="{Binding}"
                                MethodName="ClearCommand"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </MenuItem>
                    <MenuItem Style="{StaticResource BaseMenuItem}" Header="_Refresh">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Click">
                                <ei:CallMethodAction
                                TargetObject="{Binding}"
                                MethodName="RefreshCommand"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </MenuItem>
                    <MenuItem Style="{StaticResource BaseMenuItem}" Header="_Cut" 
                              Command="Cut"/>
                    <MenuItem Style="{StaticResource BaseMenuItem}" Header="_Copy" 
                              Command="Copy"/>
                    <MenuItem Style="{StaticResource BaseMenuItem}" Header="_Paste" 
                              Command="Paste"/>
                </MenuItem>
                <MenuItem Style="{StaticResource BaseMenuItem}" Header="_Tools"/>
                <MenuItem Style="{StaticResource BaseMenuItem}" Header="_Actions"/>
                <MenuItem Style="{StaticResource BaseMenuItem}" Header="_Help"/>
            </Menu>
            <Menu  Style="{StaticResource BaseMenu}"
                IsMainMenu="True"  Width="270" Height="30" KeyboardNavigation.IsTabStop="False" 
                VerticalAlignment="Top" HorizontalAlignment="Left" Background="{x:Null}">
                <MenuItem Style="{StaticResource AddNewMenuItem}" Padding="0">
                    <MenuItem Header="_New Company Type" 
                          IsEnabled="{Binding AllowNew}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Click">
                                <ei:CallMethodAction
                        TargetObject="{Binding}"
                        MethodName="NewCompanyTypeCommand"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </MenuItem>
                </MenuItem>
                <MenuItem Style="{StaticResource BaseMenuItem}"
                Click="SaveMenuItem_Click" >
                    <MenuItem.Header>
                        <Button Style="{StaticResource SaveButton}" Click="SaveMenuItem_Click">
                          
                        </Button>
                    </MenuItem.Header>
                </MenuItem>
                <MenuItem Style="{StaticResource DeleteMenuItem}" Padding="0">
                    <MenuItem Style="{StaticResource BaseMenuItem}" Header="_Delete Company Type" 
                          IsEnabled="{Binding AllowDelete}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Click">
                                <ei:CallMethodAction
                            TargetObject="{Binding}"
                            MethodName="DeleteCommand"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </MenuItem>
                </MenuItem>
                <MenuItem Style="{StaticResource BaseMenuItem}">
                    <MenuItem.Header>
                        <Button Style="{StaticResource ClearButton}">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <ei:CallMethodAction
                                    TargetObject="{Binding}"
                                    MethodName="ClearCommand"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Button>
                    </MenuItem.Header>
                </MenuItem>
                <MenuItem Style="{StaticResource BaseMenuItem}">
                    <MenuItem.Header>
                        <Button Style="{StaticResource RefreshButton}">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <ei:CallMethodAction
                                TargetObject="{Binding}"
                                MethodName="RefreshCommand"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Button>
                    </MenuItem.Header>
                </MenuItem>
                <MenuItem Style="{StaticResource BaseMenuItem}" >
                    <MenuItem.Header>
                        <Button Style="{StaticResource CutButton}" Command="Cut"/>
                    </MenuItem.Header>
                </MenuItem>
                <MenuItem Style="{StaticResource BaseMenuItem}">
                    <MenuItem.Header>
                        <Button Style="{StaticResource CopyButton}" Command="Copy"/>
                    </MenuItem.Header>
                </MenuItem>
                <MenuItem  Style="{StaticResource BaseMenuItem}">
                    <MenuItem.Header>
                        <Button Style="{StaticResource PasteButton}" Command="Paste"/>
                    </MenuItem.Header>
                </MenuItem>
            </Menu>
        </StackPanel>
        <GridSplitter Style="{StaticResource BaseVerticalGridSplitter}" Grid.Row="1" Grid.Column="0"/>
        <ListBox Style="{StaticResource BaseListBox}" Grid.Row="1" Grid.Column="0" 
            ItemsSource="{Binding CompanyTypeList}"
            SelectedItem="{Binding SelectedCompanyType}"
            SelectionMode="Single">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical">
                        <StackPanel Orientation="Horizontal">
                            <Image Height="16" Width="16">
                                <Image.Style>
                                    <Style>
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Path=IsValid}" Value="{x:Null}">
                                                <Setter Property="Image.Source" Value="/XERP.Client;component/Resources/valid.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Path=IsValid}" Value="0">
                                                <Setter Property="Image.Source" Value="/XERP.Client;component/Resources/valid.png"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Path=IsValid}" Value="1">
                                                <Setter Property="Image.Source" Value="/XERP.Client;component/Resources/error.ico" />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Path=IsValid}" Value="2">
                                                <Setter Property="Image.Source" Value="/XERP.Client;component/Resources/flag2.png" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Image.Style>
                            </Image>
                            <TextBlock Text="{Binding Path=CompanyTypeID}" >
                            </TextBlock>
                            <TextBlock Width="0"
                                Text="{Binding Path=IsValid}" Visibility="Hidden">
                            </TextBlock>
                        </StackPanel>
                        <TextBlock Style="{StaticResource BaseErrorBlock}" Height="Auto"
                                       Text="{Binding Path = NotValidMessage}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <TabControl Style="{StaticResource BaseTabControl}" Name="tabctrlMain" Grid.Column="1" Grid.Row="1">
            <TabItem  Style="{StaticResource BaseTabItem}" Name="tabDetail" Header="Detail">
                <Grid Style="{StaticResource BaseGrid}">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="46"></RowDefinition>
                        <RowDefinition Height="657*"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="171"></ColumnDefinition>
                        <ColumnDefinition Width="246*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <StackPanel Style="{StaticResource BaseStackPanel}" Grid.Row="0" 
                        Grid.ColumnSpan="2" HorizontalAlignment="Stretch" 
                        VerticalAlignment="Stretch" Orientation="Horizontal" >
                        <Button Style="{StaticResource BaseButton}" Content="Company Type..." Width="100" Height="25" Margin="10" 
                            KeyboardNavigation.IsTabStop="False">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <ei:CallMethodAction
                                      TargetObject="{Binding}"
                                      MethodName="SearchCommand"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Button>
                        <TextBox Style="{StaticResource BaseTextBox}"  Width="100" Height="20"
                            Text="{Binding Path=SelectedCompanyType.CompanyTypeID, Mode=TwoWay}"
                            MaxLength= "{Binding CompanyTypeMaxFieldValueDictionary[CompanyTypeID]}" 
                            KeyboardNavigation.TabIndex="10" Name="txtKey"></TextBox>
                    </StackPanel>
                    <StackPanel Style="{StaticResource BaseStackPanel}"
                        HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                        Orientation="Vertical" Grid.Row="1" Grid.Column="0" >
                        <TextBlock Style="{StaticResource BaseTextBlock}"
                            HorizontalAlignment="Right" VerticalAlignment="Top" Margin="8">Type:
                        </TextBlock>
                        <TextBlock Style="{StaticResource BaseTextBlock}"
                            HorizontalAlignment="Right" VerticalAlignment="Top" Margin="8">Description:
                        </TextBlock>
                        <TextBox Style="{StaticResource BaseTextBox}" 
                            Width="0" Height="0"  Name="ghost"  KeyboardNavigation.IsTabStop="False"/>
                    </StackPanel>
                    <StackPanel Style="{StaticResource BaseStackPanel}"
                        Grid.Row="1" Grid.Column="1"
                        HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                        Orientation="Vertical" IsEnabled="{Binding AllowEdit}">
                        <TextBox Style="{StaticResource BaseTextBox}"
                            HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5" Width="250"
                            Text="{Binding Path=SelectedCompanyType.Type, Mode=TwoWay}"
                            IsEnabled="{Binding AllowEdit}"
                            MaxLength= "{Binding CompanyTypeMaxFieldValueDictionary[Type]}" 
                            KeyboardNavigation.TabIndex="20" Background="White" BorderBrush="DimGray"/>
                        <TextBox Style="{StaticResource BaseTextBox}"
                            HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5" Width="250"
                            Text="{Binding Path=SelectedCompanyType.Description, Mode=TwoWay}"
                            IsEnabled="{Binding AllowEdit}"
                            MaxLength= "{Binding CompanyTypeMaxFieldValueDictionary[Description]}"
                            KeyboardNavigation.TabIndex="30" BorderBrush="DimGray"></TextBox>
                    </StackPanel>
                </Grid>
            </TabItem>
            <TabItem Style="{StaticResource BaseTabItem}" Name="tabList" Header="List" 
                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                KeyboardNavigation.IsTabStop="False">
                <Grid Style="{StaticResource BaseGrid}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="37*" />
                        <ColumnDefinition Width="354*" />
                    </Grid.ColumnDefinitions>
                    <DataGrid Style="{StaticResource BaseDataGrid}" Name="dgMain" Grid.ColumnSpan="2" Grid.Column="1"
                        ItemsSource="{Binding CompanyTypeList, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                        SelectedItem="{Binding SelectedCompanyType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                        SelectionMode="Extended" Initialized="DataGrid_Initialized" 
                        PreviewKeyUp="dgMain_PreviewKeyUp" SelectionChanged="dgMain_SelectionChanged" 
                        PreviewKeyDown="dgMain_PreviewKeyDown" AutoGenerateColumns="False">
                        <DataGrid.ContextMenu>
                            <ContextMenu >
                                <MenuItem Header="Copy Row/s" IsEnabled="{Binding AllowRowCopy}"
                                      Command="Copy">
                                </MenuItem>
                                <MenuItem Name="dgMainPasteRow" Header="Paste Row/s" IsEnabled="{Binding AllowRowPaste}" Click="dgMainPasteRow_Click">
                                </MenuItem>
                            </ContextMenu>
                        </DataGrid.ContextMenu>
                        <DataGrid.Columns>
                            <DataGridTextColumn Binding="{Binding CompanyTypeID, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
                                    Header="ID" Width="*">
                            </DataGridTextColumn>
                            <DataGridTextColumn Binding="{Binding Type, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
                                    Header="Name" Width="*">
                            </DataGridTextColumn>
                            <DataGridTextColumn Binding="{Binding Description, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
                                Header="Description" Width="*"/>
                        </DataGrid.Columns>
                    </DataGrid>
                    <TextBox Style="{StaticResource BaseTextBox}" Name="ghost2" Grid.Column="2" 
                        Height="0" Width="0" KeyboardNavigation.IsTabStop="False"/>
                </Grid>
            </TabItem>
        </TabControl>
    </Grid>
</UserControl>

